package com.stm.web.controller.toolsTest;

import java.util.Date;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.stm.common.annotation.Log;
import com.stm.common.enums.BusinessType;
import com.stm.toolsTest.domain.KfRToolsTest;
import com.stm.toolsTest.service.IKfRToolsTestService;
import com.stm.common.core.controller.BaseController;
import com.stm.common.core.page.TableDataInfo;
import com.stm.common.core.domain.AjaxResult;
import com.stm.common.utils.poi.ExcelUtil;
import com.stm.framework.util.ShiroUtils;

/**
 * 工具试验关系 信息操作处理
 * 
 * @author wyc
 * @date 2019-04-11
 */
@Controller
@RequestMapping("/toolsTest/testConclusion")
public class KfRToolsTestController extends BaseController
{
    private String prefix = "toolsTest/testConclusion";
	
	@Autowired
	private IKfRToolsTestService kfRToolsTestService;
	
	@RequiresPermissions("toolsTest:testConclusion:view")
	@GetMapping()
	public String kfRToolsTest(ModelMap mmap)
    {
    	mmap.put("user", ShiroUtils.getSysUser());
	    return prefix + "/testConclusion";
	}
	
	/**
	 * 查询工具试验关系列表
	 */
	@RequiresPermissions("toolsTest:testConclusion:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(KfRToolsTest kfRToolsTest)
	{
		startPage();
        List<KfRToolsTest> list = kfRToolsTestService.selectKfRToolsTestList(kfRToolsTest);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出工具试验关系列表
	 */
	@RequiresPermissions("toolsTest:testConclusion:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(KfRToolsTest kfRToolsTest)
    {
    	List<KfRToolsTest> list = kfRToolsTestService.selectKfRToolsTestList(kfRToolsTest);
        ExcelUtil<KfRToolsTest> util = new ExcelUtil<KfRToolsTest>(KfRToolsTest.class);
        return util.exportExcel(list, "kfRToolsTest");
    }
	
	/**
	 * 新增工具试验关系
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存工具试验关系
	 */
	@RequiresPermissions("toolsTest:testConclusion:add")
	@Log(title = "工具试验关系", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(KfRToolsTest kfRToolsTest)
	{
		kfRToolsTest.setDprtcode(ShiroUtils.getSysUser().getDeptId());
		return toAjax(kfRToolsTestService.insertKfRToolsTest(kfRToolsTest));
	}

	/**
	 * 修改工具试验关系
	 */
	@GetMapping("/edit/{toolsId}/{testId}")
	public String edit(@PathVariable("toolsId") String toolsId,@PathVariable("testId") String testId, ModelMap mmap)
	{
		KfRToolsTest kfRToolsTest = kfRToolsTestService.selectKfRToolsTestById(toolsId,testId);
		mmap.put("kfRToolsTest", kfRToolsTest);
		mmap.put("date",new Date());
		return prefix + "/edit";
	}

	/**
	 * 修改保存工具试验关系
	 */
	@RequiresPermissions("toolsTest:testConclusion:edit")
	@Log(title = "工具试验关系", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(KfRToolsTest kfRToolsTest)
	{
		return toAjax(kfRToolsTestService.updateKfRToolsTest(kfRToolsTest));
	}

	/**
	 * 删除工具试验关系
	 */
	@RequiresPermissions("toolsTest:testConclusion:remove")
	@Log(title = "工具试验关系", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(kfRToolsTestService.deleteKfRToolsTestByIds(ids));
	}
	
}
